|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
见倒数第五行,为什么查找不到路径?
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="UTF-8">
<title>注册页面</title>
</head>
<body>
<form action="RegAction" method="post" enctype="multipart/form-data">
<h1>注册页面</h1>
<h1>21 人工智能 徐家豪</h1>
<hr width="100%" size="5" color="black" >
<p style="color: #ff0000">${username}</p>
<p>${password}</p>
<p>${sex}</p>
<p>${major}</p>
<p>${like}</p>
<img src="girl.jpg" width="200px"/><br>
用户名:<input type="text" name="username"/>
<br><br>
密 码:<input type="password" name="password"/>
<br><br>
性 别:
<input type="radio" name="sex" value="男" checked/>男
<input type="radio" name="sex" value="女"/>女
<br><br>
兴 趣:<!-- 复选框 -->
<input type="checkbox" name="like" value="唱"/>唱
<input type="checkbox" name="like" value="跳"/>跳
<input type="checkbox" name="like" value="rap"/>rap
<input type="checkbox" name="like" value="篮球"/>篮球
<br><br>
学 历:<!-- 下拉列表 -->
<select name="major">
<option value="信息管理">信息管理</option>
<option value="软件工程">软件工程</option>
<option selected value="人工智能">人工智能</option>
</select>
<br><br>
简 介:<textarea rows="5" cols="20" name="introduction"></textarea>
<br><br>
文件:<input type="file" name="myFile"/>
<br><br>
<input type="submit" value="注册"/><!-- 不能有name,不然也会提交给服务器 -->
<input type="reset" value="重置"/>
</form>
</body>
</html>
package xjh.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import javax.xml.soap.SOAPElementFactory;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Date;
import java.util.UUID;
@WebServlet("/RegAction")
@MultipartConfig(location = "D:/jerbrain/img", maxFileSize = 1024 * 1024 * 5)
public class RegActionServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
System.out.println("id:" + req.getRemoteAddr());
System.out.println(new Date());
String username = req.getParameter("username");
String password = req.getParameter("password");
String sex = req.getParameter("sex");
String major = req.getParameter("major");
// String like=req.getParameter("like");
String[] like = req.getParameterValues("like");
String s = "";
if (like == null) {
s = "无";
} else {
for (String L : like) {
s += L;
s += " ";
}
}
System.out.println("username:" + username);
System.out.println("password:" + password);
System.out.println("sex:" + sex);
System.out.println("major:" + major);
System.out.println("like:" + s);
Part part = req.getPart("myFile");
String cd = part.getHeader("Content-Disposition");
// System.out.println(cd);
String filename = cd.substring(cd.lastIndexOf("=") + 2, cd.length() - 1);
// System.out.println(filename);
String filename1 = UUID.randomUUID().toString() + ".jpg";
// System.out.println(filename1);
part.write(filename1);
req.setAttribute("filename",filename1);
req.setAttribute("username", username);
req.setAttribute("password", password);
req.setAttribute("sex", sex);
req.setAttribute("major", major);
req.setAttribute("like", like);
req.getRequestDispatcher("regSuccess.jsp").forward(req, resp);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// response.setContentType("text/html;charset=UTF-8");
// request.setCharacterEncoding("UTF-8");
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注册成功</title>
</head>
<body>
<p style="color: #ff0000">${username}</p>
<ul>
<li>用户信息</li>
<li>用户名:${username}</li>
<li>密 码:${password}</li>
<li>性 别:${sex}</li>
<li>专 业:${major}</li>
<li>兴 趣:${like}</li>
<li><img src="D:/jerbrain/img/${filename}" width="200px"/></li>
<li><a href="reg.jsp">返回登入页面</a></li>
</ul>
</body>
</html>
你说的第五行是哪个?这 jsp 代码和 servlet 代码 都在
|
|